using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using iBeauty.BusinessObjects;

namespace iBeauty.DAL
{
	public class SearchSettingDAO
	{
		public SearchSettingDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<SearchSetting> GetSearchSettings()
		{
			try
			{
				List<SearchSetting> lstSearchSettings = new List<SearchSetting>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[SearchObject],[SearchCondition],[IsAddResult],[IsOnResult],[AccountId] FROM [SearchSetting]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					SearchSetting oSearchSetting = new SearchSetting();
					oSearchSetting.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oSearchSetting.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oSearchSetting.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oSearchSetting.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["SearchObject"] != DBNull.Value)
						oSearchSetting.SearchObject = Convert.ToInt32(oDbDataReader["SearchObject"]);

					if(oDbDataReader["SearchCondition"] != DBNull.Value)
						oSearchSetting.SearchCondition = Convert.ToString(oDbDataReader["SearchCondition"]);

					if(oDbDataReader["IsAddResult"] != DBNull.Value)
						oSearchSetting.IsAddResult = Convert.ToString(oDbDataReader["IsAddResult"]);

					if(oDbDataReader["IsOnResult"] != DBNull.Value)
						oSearchSetting.IsOnResult = Convert.ToString(oDbDataReader["IsOnResult"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oSearchSetting.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);
					lstSearchSettings.Add(oSearchSetting);
				}
				oDbDataReader.Close();
				return lstSearchSettings;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public SearchSetting GetSearchSetting(string ID)
		{
			try
			{
				SearchSetting oSearchSetting = new SearchSetting();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[SearchObject],[SearchCondition],[IsAddResult],[IsOnResult],[AccountId] FROM [SearchSetting] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oSearchSetting.ID = Convert.ToString(oDbDataReader["ID"]);

					if(oDbDataReader["CreateDate"] != DBNull.Value)
						oSearchSetting.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

					if(oDbDataReader["ModifiedDate"] != DBNull.Value)
						oSearchSetting.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

					if(oDbDataReader["TimeStamp"] != DBNull.Value)
						oSearchSetting.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

					if(oDbDataReader["SearchObject"] != DBNull.Value)
						oSearchSetting.SearchObject = Convert.ToInt32(oDbDataReader["SearchObject"]);

					if(oDbDataReader["SearchCondition"] != DBNull.Value)
						oSearchSetting.SearchCondition = Convert.ToString(oDbDataReader["SearchCondition"]);

					if(oDbDataReader["IsAddResult"] != DBNull.Value)
						oSearchSetting.IsAddResult = Convert.ToString(oDbDataReader["IsAddResult"]);

					if(oDbDataReader["IsOnResult"] != DBNull.Value)
						oSearchSetting.IsOnResult = Convert.ToString(oDbDataReader["IsOnResult"]);

					if(oDbDataReader["AccountId"] != DBNull.Value)
						oSearchSetting.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);
				}
				oDbDataReader.Close();
				return oSearchSetting;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddSearchSetting(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,int?SearchObject,string SearchCondition,string IsAddResult,string IsOnResult,int?AccountId)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [SearchSetting]([CreateDate],[ModifiedDate],[TimeStamp],[SearchObject],[SearchCondition],[IsAddResult],[IsOnResult],[AccountId])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@SearchObject,@SearchCondition,@IsAddResult,@IsOnResult,@AccountId)",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (SearchObject.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,SearchObject));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,DBNull.Value));
				if (SearchCondition!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,SearchCondition));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,DBNull.Value));
				if (IsAddResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,IsAddResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,DBNull.Value));
				if (IsOnResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,IsOnResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddSearchSetting(SearchSetting oSearchSetting)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [SearchSetting]([CreateDate],[ModifiedDate],[TimeStamp],[SearchObject],[SearchCondition],[IsAddResult],[IsOnResult],[AccountId])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@SearchObject,@SearchCondition,@IsAddResult,@IsOnResult,@AccountId)",CommandType.Text);
				if (oSearchSetting.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oSearchSetting.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oSearchSetting.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oSearchSetting.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oSearchSetting.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oSearchSetting.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oSearchSetting.SearchObject.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,oSearchSetting.SearchObject));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,DBNull.Value));
				if (oSearchSetting.SearchCondition!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,oSearchSetting.SearchCondition));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,DBNull.Value));
				if (oSearchSetting.IsAddResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,oSearchSetting.IsAddResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,DBNull.Value));
				if (oSearchSetting.IsOnResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,oSearchSetting.IsOnResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,DBNull.Value));
				if (oSearchSetting.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oSearchSetting.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateSearchSetting(string ID,DateTime?CreateDate,DateTime?ModifiedDate,DateTime?TimeStamp,int?SearchObject,string SearchCondition,string IsAddResult,string IsOnResult,int?AccountId)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [SearchSetting] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[SearchObject]=@SearchObject,[SearchCondition]=@SearchCondition,[IsAddResult]=@IsAddResult,[IsOnResult]=@IsOnResult,[AccountId]=@AccountId WHERE [ID]=@ID",CommandType.Text);
				if (CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (SearchObject.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,SearchObject));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,DBNull.Value));
				if (SearchCondition!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,SearchCondition));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,DBNull.Value));
				if (IsAddResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,IsAddResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,DBNull.Value));
				if (IsOnResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,IsOnResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,DBNull.Value));
				if (AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateSearchSetting(SearchSetting oSearchSetting)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [SearchSetting] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[SearchObject]=@SearchObject,[SearchCondition]=@SearchCondition,[IsAddResult]=@IsAddResult,[IsOnResult]=@IsOnResult,[AccountId]=@AccountId WHERE [ID]=@ID",CommandType.Text);
				if (oSearchSetting.CreateDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,oSearchSetting.CreateDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate",DbType.DateTime,DBNull.Value));
				if (oSearchSetting.ModifiedDate.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,oSearchSetting.ModifiedDate));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate",DbType.DateTime,DBNull.Value));
				if (oSearchSetting.TimeStamp.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,oSearchSetting.TimeStamp));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp",DbType.DateTime,DBNull.Value));
				if (oSearchSetting.SearchObject.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,oSearchSetting.SearchObject));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchObject",DbType.Int32,DBNull.Value));
				if (oSearchSetting.SearchCondition!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,oSearchSetting.SearchCondition));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SearchCondition",DbType.String,DBNull.Value));
				if (oSearchSetting.IsAddResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,oSearchSetting.IsAddResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAddResult",DbType.String,DBNull.Value));
				if (oSearchSetting.IsOnResult!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,oSearchSetting.IsOnResult));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsOnResult",DbType.String,DBNull.Value));
				if (oSearchSetting.AccountId.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,oSearchSetting.AccountId));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId",DbType.Int32,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oSearchSetting.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveSearchSetting(SearchSetting oSearchSetting)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [SearchSetting] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,oSearchSetting.ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveSearchSetting(string ID)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [SearchSetting] WHERE [ID]=@ID",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID",DbType.String,ID));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
